import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('views/Home.vue')
  },
  {
    path: '/admin-login',
    name: 'AdminLogin',
    component: () => import('views/AdminView/AdminLogin.vue')
  },
  {
    path: '/admin',
    name: 'Admin',
    component: () => import('views/AdminView/Admin.vue'),
    redirect: '/finish-data',    // 重定向路由
    children: [
      {
        path: '/finish-data',
        name: 'FinishData',
        component: () => import('views/AdminView/FinishData.vue')
      },
      {
        path: '/un-finish-data',
        name: 'UnFinishData',
        component: () => import('views/AdminView/UnFinishData.vue')
      },
      {
        path: '/filter',
        name: 'Filter',
        component: () => import('views/AdminView/Filter.vue')
      }
    ],

    // 导航守卫
    beforeEnter: (to, from, next) => {
      if (to.name !== '/admin-login' && !sessionStorage.username) next({ name: 'AdminLogin' });
      else next();
    }
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
